'use strict';

angular.module('app')
	.controller('funcController', [ '$rootScope', '$scope', '$http', '$state',
	                                function($rootScope, $scope, $http, $state) {
		$scope.title = '功能管理';
        $scope.param = { };
        $scope.loading = false;
        
		$scope.search = function () {
	        $scope.loading = true;
			$.ajax({
				url : $scope.app.project_name + '/hFunc/read/list',
				data: $scope.param
			}).then(function(result) {
		        $scope.loading = false;
				if (result.httpCode == 200) {
					$scope.pageInfo = result.data;
				} else {
					$scope.msg = result.msg;
				}
				$scope.$apply();
			});
		}
		
		$scope.searchRe = function () {
	        $scope.loading = true;
	        $scope.param.pageNum = 1;
	        
	        $.ajax({
				url : $scope.app.project_name + '/hFunc/read/list',
				data: $scope.param
			}).then(function(result) {
		        $scope.loading = false;
				if (result.httpCode == 200) {
					$scope.pageInfo = result.data;
				} else {
					$scope.msg = result.msg;
				}
				$scope.$apply();
			});
		}
		
		$scope.search();
		
		$scope.clearSearch = function() {
			$scope.param={};
			$scope.param.keyword = null;
			$scope.search();
		}
		
		$scope.enableFunc = function(funcNo, enable) {
        	var msg = '';
        	if (enable == 'Y') {
        		msg = '启用';
        	}
        	
        	if (enable == 'N') {
        		msg = '停用';
        	}
        	
        	$scope.alertMessage({
                text:"确定要" + msg + "该功能吗？", //内容
                btnCancel:true, //取消按钮
                btnConfirm:true //确认按钮
            }).then(function () {
    			$.ajax({
    				url : $scope.app.project_name + '/hFunc/update/enableFunc',
    				data: {'funcNo': funcNo, 'enable':enable}
    			}).then(function(result) {
    		        $scope.loading = false;
    				if (result.httpCode == 200) {
    					$scope.param.keyword = null;
    					$scope.search();
    				} else {
    					$scope.msg = result.msg;
    				}
    			});
            })
        }
		
		// 翻页
        $scope.pagination = function (page) {
            $scope.param.pageNum = page;
            $scope.search();
        };

	} ]);